#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2016-11-11 16:38:36
# @Author  : PiaoYun (piaoyunsoft@163.com)
# @Link    : http://www.dllhook.com
# @Version : $Id$

import hmac
import hashlib
from Crypto.Hash import HMAC
from Crypto.Hash import MD2
from Crypto.Hash import MD4
from Crypto.Hash import MD5
from Crypto.Hash import RIPEMD
from Crypto.Hash import SHA
from Crypto.Hash import SHA224
from Crypto.Hash import SHA256
from Crypto.Hash import SHA384
from Crypto.Hash import SHA512


message = b"www.chinapyg.com"

def defaultHMAC():
	h = hmac.new(b'piaoyun')
	h.update(message)
	print h.hexdigest().upper()

def pyCryptoHMAC():
	secret = b'piaoyun'
	h = HMAC.new(secret)
	h.update(message)
	print h.hexdigest().upper()

def _MD(type):
	h = None
	if type == 2:
		h = MD2.new()
	elif type == 4:
		h = MD4.new()
	elif type == 5:
		h = MD5.new()

	h.update(message)
	print h.hexdigest().upper()

def _RIPEMD():
	h = RIPEMD.new()
	h.update(message)
	print h.hexdigest().upper()

def _SHA(type):
	h = None
	if type == 1:
		h = SHA.new()
	elif type == 224:
		h = SHA256.new()
	elif type == 256:
		h = SHA256.new()
	elif type == 384:
		h = SHA384.new()
	elif type == 512:
		h = SHA512.new()

	h.update(message)
	print h.hexdigest().upper()

if __name__ == '__main__':
	print("====HMAC Test====")
	defaultHMAC()
	pyCryptoHMAC()
	print("====MD Test====")
	_MD(2)
	_MD(4)
	_MD(5)
	print("====RIPEMD Test====")
	_RIPEMD()
	print("====SHA Test====")
	_SHA(1)
	_SHA(224)
	_SHA(256)
	_SHA(384)
	_SHA(512)

	print("====hashlib Test====")
	h = hashlib.md5()
	h.update(message)
	print h.hexdigest().upper()
	print h.digest().encode('hex').upper()